<!DOCTYPE html>
<html lang="en">

<head>
    <#include "/lx/admin/components/meta.html" />
    <title>录取标准详情 ${metaTitleSuffix!}</title>
    <#include "/lx/admin/components/stylesheets.html" />
</head>

<body>
    <div id="app">
        <el-container>
            <#assign menuIndex="3-1" />
            <#include "/lx/admin/components/menu.html" />
            <el-container>
                <#include "/lx/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-form ref="form" :model="info" label-width="100px">
                            <el-form-item label="专业">
                                <el-radio-group v-model="isNewMajor" size="mini" :disabled="editMode">
                                    <el-radio-button :label="false">已有标准新增排名</el-radio-button>
                                    <el-radio-button :label="true">新增录取标准</el-radio-button>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item label="">
                                <el-select v-model="info.majorId" filterable clearable placeholder="专业" style="width: 600px;" :disabled="editMode" v-if="!isNewMajor">
                                    <el-option v-for="(item, index) in schoolMajors" :key="item.id" :label="item.name" :value="item.id"></el-option>
                                </el-select>
                                <div v-else>
                                    <el-input v-model="newMajor.department" placeholder="请输入学院"></el-input>
                                    <el-checkbox v-model="isNoMore">该学院下所有专业要求一致</el-checkbox><br />
                                    <el-select v-model="newMajor.name" filterable clearable allow-create placeholder="课程名称" style="width: 600px; margin-bottom: 15px;" :disabled="isNoMore">
                                        <el-option v-for="(item, index) in majors" :key="item.id" :label="item.englishName" :value="item.englishName"></el-option>
                                    </el-select><br />
                                    <el-select v-model="newMajor.type" filterable clearable placeholder="专业大类">
                                        <el-option v-for="(item, index) in types" :key="index" :label="item" :value="index"></el-option>
                                    </el-select>
                                </div>
                            </el-form-item>
                            <el-form-item label="最高排名">
                                <el-input v-model="info.minRank" type="number" placeholder="请输入最高排名"></el-input>
                            </el-form-item>
                            <el-form-item label="最低排名">
                                <el-input v-model="info.maxRank" type="number" placeholder="请输入最低排名"></el-input>
                            </el-form-item>
                            <el-form-item label="成绩要求">
                                <el-input v-model="info.score" placeholder="请输入成绩要求（如无其他要求，无需%号）"></el-input>
                            </el-form-item>
                            <el-form-item label="专业背景要求">
                                <el-input v-model="info.requirement" type="textarea" :autosize="{ minRows: 10 }" placeholder="请输入专业背景要求"></el-input>
                            </el-form-item>
                            <el-form-item>
                                <el-button type="primary" @click="submit">提交</el-button>
                            </el-form-item>
                        </el-form>
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <#include "/lx/admin/components/footer.html" />
    </div>
    <#include "/lx/admin/components/scripts.html" />
    <script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data() {
            return {
                ukSchoolId: '${ukSchoolId!}',
                editMode: false,
                info: {},
                isNewMajor: false,
                newMajor: {
                    name: '',
                    department: '',
                    type: ''
                },
                isNoMore: false,
                schoolMajors: [],
                majors: [],
                types: [
                    "Arts & Humanities　艺术类",
                    "Education　教育类",
                    "Law　法律类",
                    "Psychology　心理学类",
                    "Business & Economics　商业与经济类",
                    "Clinical, Pre-clinical & Health　医学健康类",
                    "Computer Science　计算机科学类",
                    "Engineering & Technology　工程与科学类",
                    "Life Sciences　生命科学类",
                    "Natural Science　自然科学类",
                    "Social Sciences　社会科学类"
                ]
            }
        },
        watch: {
            isNoMore: function (val) {
                if (val) {
                    this.newMajor.name = this.newMajor.department;
                } else {
                    this.newMajor.name = '';
                }
            }
        },
        mounted: function() {
            this.info = ${info!'{}'}
            this.schoolMajors = ${schoolMajors!'[]'}
            this.majors = ${majors!'[]'}

            if (this.info.id) {
                this.editMode = true;
            }
            if (this.info.requirement) {
                this.info.requirement = this.info.requirement.replace(/<br \/>/g, '\n');
            }
            if (this.info.extra) {
                this.info.score = this.info.extra;
            }
        },
        methods: {
            submit() {
                var self = this;
                if (self.isNewMajor) {
                    if (!self.newMajor.name) {
                        msg("请输入课程名称");
                        return;
                    }
                    if (!self.newMajor.department) {
                        msg("请输入所属学院");
                        return;
                    }

                } else {
                    if (!self.info.majorId) {
                        msg("请选择专业");
                        return;
                    }
                }
                if (!self.info.minRank) {
                    msg("请输入最高排名");
                    return;
                }
                if (!self.info.maxRank) {
                    msg("请输入最低排名");
                    return;
                }
                if (self.info.minRank > self.info.maxRank) {
                    msg("最高排名必须小于等于最低排名");
                    return;
                }
                if (!self.info.score) {
                    msg("请输入成绩要求");
                    return;
                }

                var url = "/lx/admin/rank/updateRankScore"
                var param = {
                    majorRankScoreId: self.info.id,
                    ukSchoolId: self.ukSchoolId,

                    isNewMajor: self.isNewMajor ? 1 : 0,

                    majorId: self.info.majorId,
                    minRank: self.info.minRank,
                    maxRank: self.info.maxRank,
                    score: self.info.score,
                    requirement: self.info.requirement ? self.info.requirement.replace(/\n/g, '<br />') : ''
                };
                if (self.isNewMajor) {
                    param.majorIsNoMore = self.isNoMore ? 1 : 0;
                    param.majorName = self.newMajor.name;
                    param.majorDepartment = self.newMajor.department;
                    param.majorType = self.newMajor.type;
                }
                var success = (response) => {
                    if ('${referer!}' != '') {
                        window.location.href = '${referer!}';
                    } else {
                        // window.location.href = "/lx/admin/policy/list";
                        window.location.href = "/lx/admin/school/list";
                    }
                }
                var fail = (response) => {
                    msg(response.msg);
                }
                var complete = () => {}
                axiosRequestPro(url, param, success, fail, complete);
            }
        }
    })
    </script>
    <style type="text/css">
    .title {
        font-size: 18px;
        font-weight: bold;
    }

    .container {
        padding-bottom: 100px;
    }

    .row {
        margin-bottom: 22px;
    }

    .label {
        width: 100%;
        font-size: 14px;
        color: #606266;
        line-height: 40px;
        padding: 0 12px 0 0;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
    }

    input[type="file"] {
        display: none !important;
    }

    .image-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .image-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    .image-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }

    .image {
        width: 178px;
        height: 178px;
        display: block;
    }
    </style>
    <#include "/lx/admin/components/msg.html" />
</body>

</html>